#ifndef __ARP_HANDLE__
#define __ARP_HANDLE__

#include "tools.h"
#include "get_interface.h"
#include <linux/if_ether.h> // ETH_ALEN
typedef struct ARP_LIST
{
    union IP ip;           // 保存ip地址
    unsigned char mac[6];  // 保存mac地址
    struct ARP_LIST *next; // 指向下一个地址
} arp_node;                // arp链表节点

typedef struct
{
    int size;       // arp表元素个数
    arp_node *next; // 数据
} arp_list_head;    // arp链表头

typedef struct
{
    unsigned short int ar_hrd; /* Format of hardware address.  */
    unsigned short int ar_pro; /* Format of protocol address.  */
    unsigned char ar_hln;      /* Length of hardware address.  */
    unsigned char ar_pln;      /* Length of protocol address.  */
    unsigned short int ar_op;  /* ARP opcode (command).  */
#if 1
    /* Ethernet looks like this : This bit is variable sized
       however...  */
    unsigned char __ar_sha[ETH_ALEN]; /* Sender hardware address.  */
    unsigned char __ar_sip[4];        /* Sender IP address.  */
    unsigned char __ar_tha[ETH_ALEN]; /* Target hardware address.  */
    unsigned char __ar_tip[4];        /* Target IP address.  */
#endif
} ARPHDR; // arp报文

extern arp_list_head *arp_head;                                 // 链表头
extern arp_list_head *init_arp_list_head();                     // 初始化链表头
int insert_arp_list(unsigned char ip[4], unsigned char mac[6]); // 插入map和ip数据
extern void print_arp_list();                                   // 输出arp表数据
extern arp_node *find_arp_ip(unsigned char ip[4]);              // 查询ip对应的mac地址

void *arp_recv(void *arg);                                                                                     // 处理arp请求
extern int arp_send(int sockfd, unsigned short op, unsigned char ip[4], unsigned char mac[6], INTERFACE *eth); // 发送arp报文

#endif // !__ARP_HANDLE__
#define __ARP_HANDLE__